<template>
  <div class="bindww">
    <div class="uploadimg">
      <div class="right same">
        <div v-show="tbload=='LOADING'">
          <div class="identity loadTb"></div>
          <span>淘宝会员名</span>
        </div>
        <div v-show="tbload=='AFTERLOAD'">
          <div class="identity">
            <img :src="tbimg" alt="" style="width:100%;height:100%;">
          </div>
          <span>淘宝会员名</span>
        </div>
        <van-uploader v-show="tbload=='BEFORELOAD'" :max-count="1" :after-read="afterReadTb" :before-read="beforeReadTb">
          <div class="identity bm"></div>
				  <span>淘宝会员名</span>
        </van-uploader>
      </div>
    </div>
    <div class="submit">
      <van-button type="primary" block @click="onSubmit" color="#4b7ee9">绑定</van-button>
    </div>
  </div>
</template>
<script>
export default {
  data(){
    return{
      tbload:'BEFORELOAD',
      tbimg:'',
    }
  },
  methods:{
    //淘宝旺旺上传之前
    beforeReadTb(file){
      if (file.type.indexOf("image") == -1) {
        this.$toast('请上传正确的图片格式');
        return false;
      }
      return true;
    },
    //淘宝旺旺上传
    afterReadTb(file) {
      this.tbload = 'LOADING'
      this.uploadtb(file.file)
    },
    uploadtb(file){
      let params = new FormData()
      params.append('file', file)
      let config = {
            headers: {
              'Content-Type': 'multipart/form-data'
            }
          }
      return new Promise((resolve, reject) => {
        axios.post('api/v1/register/tbimageRecognition', params, config).then(res => {
          console.log('上传',res)
          this.tbload = 'AFTERLOAD'
          if(res.data.Status == 200){
            this.$toast('上传成功')
            this.tbimg = res.data.UrlImg
            console.log('this.tbimg',this.tbimg)
          }else{
            this.$toast(res.data.Message)
            this.tbload = 'BEFORELOAD'
          }
        })
      })
    },
    onSubmit(){

    }
  }
}
</script>
<style lang="stylus" scoped>
.bindww{
  height 100%
  font-size 12px
  .submit{
		margin:18px;
	}
}
</style>


